package com.example.sprintboot.mapper;

import com.example.sprintboot.entity.Gourmet;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GourmetMapper {
    // 使用 XML 映射文件进行关联查询
    List<Gourmet> selectAll();

    Gourmet selectById(Integer id);

    @Insert("insert into `gourmet` (user_id,category_id,title,content,image,is_audit,is_public,create_time" +
            ",view_count,like_count,upvot_count,rating) " +
            "values (#{userId},#{categoryId},#{title},#{content},#{image},#{isAudit}," +
            "#{isPublic},#{createTime},#{viewCount},#{likeCount},#{upvotCount},#{rating})")
    void add(Gourmet gourmet);

    @Update("update `gourmet` set  user_id=#{userId},category_id=#{categoryId}," +
            "title=#{title},content=#{content},image=#{image},is_audit=#{isAudit}," +
            "is_public=#{isPublic},view_count=#{viewCount},like_count=#{likeCount},upvot_count=#{upvotCount},rating=#{rating}" +
            " where id=#{id}")
    void update(Gourmet gourmet);

    @Delete("delete from `gourmet` where id = #{id}")
    void delete(Integer id);

    List<Gourmet> query(@Param("title") String title);
    
    @Update("update `gourmet` set is_audit=#{isAudit} where id=#{id}")
    void updateAuditStatus(@Param("id") Integer id, @Param("isAudit") Integer isAudit);
}
